package net.steam.easyjoboa.web.action;

import java.util.Date;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import net.steam.easyjoboa.biz.VoteBiz;
import net.steam.easyjoboa.entity.Vote;

public class VoteAction {
	private VoteBiz voteBiz;
	private List<Vote> list;
	private Vote vote;
	private int id;
	
	//添加投票属性
	private String voteName;
	private String voteContent;
	private Date startDate;
	private Date endDate;
	private String voteStatus;
	

	
	/*
	 * 投票选项列表
	 */
	@Action(value="voteList",results={@Result(name="success",location="../../vote/voteListByAdmin.jsp")})
	public String listVote(){
		list=voteBiz.getVotesList();
		return "success";
	}
	
	/*
	 * 投票选项列表
	 */
	@Action(value="toVoteList",results={@Result(name="success",location="../../vote/voteList.jsp")})
	public String toVoteList(){
		list=voteBiz.getVotesList();
		return "success";
	}

	
	/*
	 * 添加投票
	 */
	@Action(value="addVote",results={@Result(name="success",location="voteList",type="redirectAction")})
	public String addVote(){
		Vote vote = new Vote();
		vote.setVoteName(voteName);
		vote.setVoteContent(voteContent);
		vote.setVoteStartDate(startDate);
		vote.setVoteEndDate(endDate);
		vote.setVoteStatus("0");		
		voteBiz.addVote(vote);
		return "success";
	}
	
	//根据投票id得到投票
	@Action(value="getVoteById",results={@Result(name="success",location="../../vote/adminUpdateVote.jsp")})
	public String getVoteVyId(){
		vote=voteBiz.getVote(id);
		vote.getVoteContent().trim();
		return "success";
	}
	
	/*
	 * 修改
	 */
	@Action(value="updateVote",results={@Result(name="success",location="voteList",type="redirectAction")})
	public String updateVote(){
		Vote vote = new Vote();
		vote=voteBiz.getVote(id);
		vote.setVoteName(voteName);
		vote.setVoteContent(voteContent);
		vote.setVoteStartDate(startDate);
		vote.setVoteEndDate(endDate);
		vote.setVoteStatus(voteStatus);
		voteBiz.updateVote(vote);
		return "success";
	}
	
	/*
	 * 删除
	 */
	@Action(value="deleteVote",results={@Result(name="success",location="voteList",type="redirectAction")})
	public String deleteAction(){
		vote=voteBiz.getVote(id);
		voteBiz.deleteVote(vote);
		return "success";
	}
	
	
	
	//get set 方法
	public List<Vote> getList() {
		return list;
	}
	public void setList(List<Vote> list) {
		this.list = list;
	}
	public void setVoteBiz(VoteBiz voteBiz) {
		this.voteBiz = voteBiz;
	}


	public String getVoteName() {
		return voteName;
	}


	public void setVoteName(String voteName) {
		this.voteName = voteName;
	}


	public String getVoteContent() {
		return voteContent;
	}


	public void setVoteContent(String voteContent) {
		this.voteContent = voteContent;
	}

	public Vote getVote() {
		return vote;
	}
	public void setVote(Vote vote) {
		this.vote = vote;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getVoteStatus() {
		return voteStatus;
	}

	public void setVoteStatus(String voteStatus) {
		this.voteStatus = voteStatus;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	
}
